﻿using System.Windows.Input;
using RG.Common.Configuration;
using RG.Common.WPF.Commands;
using RG.Common;
using RG.Common.Configuration;
using RG.Common.WPF;

namespace RG.Common.WPF.Workplaces
{
    public interface IFrameForMultiWorkplace: IWorkplaceObject
    {
        string Name { get; set; }
    }
    
    public interface IListFrame : IFrameForMultiWorkplace
    {
        WorkplaceWorker Worker { get; set; }
    }

    public class FrameDescVM : TreeViewItemViewModel
    {
        public FrameDescVM(TreeViewItemViewModel parent): base(parent)
        {}

        public FrameDesc Item { get; set; }

        public string Name { get; set; }

        public FrameConfigSettings Config { get; set; }

        public IFrameSettingsService SettingsService { get; set; }
    }

    public delegate void FrameTabSelectionArgs(FrameTab item);

    [SupportDataBinding]
    public class FrameTab
    {
        public event FrameTabSelectionArgs OnFrameTabSelectted;

        public ICommand SelectCmd { get; set; }

        public FrameTab()
        {
            IsFree = true;
            SelectCmd = new DelegateCommand(() => { if (OnFrameTabSelectted != null) OnFrameTabSelectted(this); });
        }

        public object View { get; set; }

        public int HistoryIndex { get; set; }
        public int SettingsIndex { get; set; }

        private object presenter;
        public object Presenter
        {
            get { return presenter; }
            set
            {
                presenter = value;
                if (Presenter is IListFrame)
                    ((IListFrame) Presenter).Worker.Worker.StateChanged += OnStateChanged;

            }
        }

        public int Num { get; set; }

        public bool IsFree { get; set; }

        private void OnStateChanged(object sender, bool isFree)
        {
            IsFree = isFree;
        }

        /// <summary>
        /// FrameDescVM который породил этот таб
        /// </summary>
        public FrameDescVM FrameDescVM { get; set; }

        public IApplicationSettings ViewSettings { get; set; }

        public IApplicationSettings PresenterSettings { get; set; }

        public FrameConfigSettings Config { get; set; }

    }

}
